<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>车类型</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="jq.js"></script>
    <script>
        $(function () {
            loaddata()
        })

        function loaddata() {
            $.getJSON("http://localhost:8080/cartype/all", function (res) {
                console.log(res)
                $("#list").empty()
                res.data.forEach(item => {
                    $("#list").append(`
                        <li>${item.tid}  ${item.name}
                            <button class="btn btn-primary" onclick="updateCartype(${item.tid})">修改</button>
                            <button class="btn btn-danger" onclick="delCartype(${item.tid})">删除</button>
                        </li>`)
                })
            })
        }

        function updateCartype(tid){
            // alert(tid)
            location.href = 'cartypeEdit.html?tid='+tid
        }

        function delCartype(tid){
            if (confirm(`tid:${tid} 确认要删除吗?`)){
                $.ajax({
                    url: 'http://localhost:8080/cartype/delete',
                    type: 'DELETE',
                    data:{
                        tid:tid
                    },
                    dataType:'JSON',
                    success: function (res) {
                        console.log(res)
                        alert('删除成功')
                        loaddata()
                    }
                })
            }
        }


    </script>
</head>
<body>
<a href="cartypeEdit.html" class="btn btn-primary btn-lg" role="button">新增</a>
<ul id="list">
    <li>aaa235
        <button >修改</button>
        <button>删除</button>
    </li>
</ul>
</body>
</html>